﻿<?php

class ControleTipoImovel {

	public function cadastrar(TipoImovel $tipo_imovel) {		
		
		include_once("../conexao/config.php");
		$conexao = new Config();
		
		$query = "insert into tipo_imovel values(NULL, ?)";
		
		$stmt = $conexao->conectar()->prepare($query);
		
		$stmt->bindValue(1, $tipo_imovel->getDescricao());
		
		$stmt->execute();
				
	}
	
	function pesquisar() {		
		
		include_once("../conexao/config.php");
		$conexao = new Config();
		
		$query = "select * from tipo_imovel";
		
		$stmt = $conexao->conectar()->prepare($query);				
		
		$stmt->execute();
		
		return $stmt;
				
	}
	
	public function pesquisarById(TipoImovel $tipo_imovel) {		
		$this->$id = $id;
		
		include_once("../conexao/config.php");
		$conexao = new Config();
		
		$query = "select * from tipo_imovel where id_tipo = ?";
		
		$stmt = $conexao->conectar()->prepare($query);
		
		$stmt->bindValue(1, $tipo_imovel->getId());
		
		$stmt->execute();
		
		return $stmt;
				
	}
	
	public function pesquisarByNome(TipoImovel $tipo_imovel) {				
		
		include_once("../conexao/config.php");
		$conexao = new Config();
		
		if($tipo_imovel->getDescricao() == '') {
			$query = "select * from tipo_imovel";
			$stmt = $conexao->conectar()->prepare($query);	
		} else {
			$query = "select * from tipo_imovel like ?";			
			$stmt = $conexao->conectar()->prepare($query);	
			
			$stmt->bindValue(1, $tipo_imovel->getDescricao());
		}
		
		$stmt = $conexao->conectar()->prepare($query);						
		
		$stmt->execute();
		
		return $stmt;
				
	}
	
	public function alterar(TipoImovel $tipo_imovel) {
		
		include_once("..conexao/config.php");
		$conexao = new Config();
		
		$query = "update tipo_imovel set nome_tipo = ? where id_tipo = ?";
		
		$stmt = $conexao->conectar()->prepare($query);
		
		$stmt->bindValue(1, $tipo_imovel->getDescricao());
		$stmt->bindValue(2, $tipo_imovel->getId());
		
		$stmt->execute();
		
	}
	
	public function remover($id) {
		
		include_once("..conexao/config.php");
		$conexao = new Config();
		
		$query = "delete tipo_imovei whoere id_tipo = ?";
		
		$stmt = $conexao->conectar()->prepare($query);
		
		$stmt->bindValue(1, $id);
		
		$stmt->execute();
		
	}	
	
}
?>